package com.finals.function.util;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.support.v4.app.NotificationCompat;

import com.finals.function.R;
import com.finals.function.app.BaseApplication;

public class NotificationUtil {

	NotificationCompat.Builder mBuilder;

	BaseApplication mApplication;

	NotificationManager mNotificationManager;

	public NotificationUtil(BaseApplication mApplication) {
		this.mApplication = mApplication;
		mBuilder = new NotificationCompat.Builder(mApplication);
		mNotificationManager = (NotificationManager) mApplication.getSystemService(Context.NOTIFICATION_SERVICE);
	}

	public void showNotification(String title, String content, PendingIntent mIntent, int id) {
		mBuilder
		/**
		 * 设置标题
		 */
		.setContentTitle(title)
		/**
		 * Finals 设置内容
		 */
		.setContentText(content)
		/**
		 * Finals 设置小图标
		 */
		.setSmallIcon(R.drawable.ic_launcher)
		/**
		 * 设置Intent
		 */
		.setContentIntent(mIntent)
		/**
		 * 设置什么时候
		 */
		.setWhen(System.currentTimeMillis())
		/**
		 * 是否自动取消
		 */
		.setAutoCancel(true)
		/**
		 * 设置声音
		 */
		.setDefaults(Notification.DEFAULT_SOUND);
		Notification mNotification = mBuilder.build();
		mNotificationManager.notify(id, mNotification);
	}

	public void onDestory() {
		if (mNotificationManager != null) {
			mNotificationManager.cancelAll();
		}
	}
}
